# 别人写的
class Solution:
    def isMatch(self, s: str, p: str) -> bool:
        if not p: return not s
        # 第一个字母是否匹配
        first_match = bool(s and p[0] in {s[0],'.'})
        # 如果 p 第二个字母是 *
        if len(p) >= 2 and p[1] == "*":
            return self.isMatch(s, p[2:]) or \
            first_match and self.isMatch(s[1:], p)
        else:
            return first_match and self.isMatch(s[1:], p[1:])

def test_1():
    assert Solution().isMatch("sss", "sss")
    assert Solution().isMatch("sss", "...")

def test_2():
    assert Solution().isMatch("sss", "s*")
    assert Solution().isMatch("sssb", "ss*b")
    assert Solution().isMatch("sssb", "s*b")
    assert Solution().isMatch("sss", "sss*")
    assert Solution().isMatch("abbcddefg", "c*ab*cd*ef.")
    assert Solution().isMatch("abc", "a.*")
    assert not Solution().isMatch("abc", "a*c")

def test_3():

    assert Solution().isMatch("ab", ".*")

if __name__ == "__main__":
    s = Solution().isMatch("aab", "c*a*b")
    assert s